package org.jeeasy.generate.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.jeeasy.common.core.annotation.dict.DictTranslation;
import org.jeeasy.common.core.base.SimpleCurdController;
import org.jeeasy.common.core.domain.model.QueryPageModel;
import org.jeeasy.common.core.domain.vo.R;
import org.jeeasy.generate.domain.GenModule;
import org.jeeasy.generate.service.GenModuleService;
import org.springframework.web.bind.annotation.*;

/**
 * @author AlpsDDJ
 * @date 2023/12/14
 */
@RestController
@Tag(name = "代码生成-模块信息")
@RequestMapping("/gen/module")
public class GenModuleController extends SimpleCurdController<GenModuleService, GenModule> {

    @GetMapping
    @DictTranslation
    @Operation(summary = "模块信息列表")
    public R<IPage<GenModule>> list(QueryPageModel queryPageModel) {
        return R.ok(super.queryPage(queryPageModel));
    }

    @GetMapping("/{id}")
    @DictTranslation
    @Operation(summary = "根据ID查找模块信息")
    public R<GenModule> info(@PathVariable("id") String id) {
        return R.ok(super.getById(id));
    }

    @GetMapping("/findByCode/{code}")
    @DictTranslation
    @Operation(summary = "根据code查找模块信息")
    public R<GenModule> findByCode(@PathVariable("code") String code) {
        return R.ok(service.getByCode(code));
    }

    @PutMapping
    @Operation(summary = "编辑模块信息")
    public R<Void> edit(@RequestBody GenModule entity) {
        super.update(entity);
        return R.ok();
    }

    @PostMapping
    @Operation(summary = "添加模块信息")
    public R<Void> add(@RequestBody GenModule entity) {
        super.insert(entity);
        return R.ok();
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "根据ID删除模块信息")
    public R<Void> remove(@PathVariable("id") String id) {
        super.deleteById(id);
        return R.ok();
    }

    @DeleteMapping("/batch")
    @Operation(summary = "批量删除模块信息")
    public R<Void> batchRemove(@RequestParam(name = "ids") String ids) {
        super.batchDelete(ids);
        return R.ok();
    }
}
